﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Model;
using Meraz.Core.Data;


namespace Meraz.Core.Repositories
{
    public interface ITwitterStudyRepository : IStudyRepository<TwitterStudy> { }
    public class TwitterStudyRepository : EFRepositoryBase<TwitterStudy, int>, ITwitterStudyRepository
    {
        public TwitterStudyRepository() { }

        public override TwitterStudy GetById(int id)
        {
            TwitterStudy obj = context.TwitterStudies
                .Where(where1 => where1.ID == id)
                .FirstOrDefault();
            return obj;
        }
        public TwitterStudy GetByName(string name)
        {
            TwitterStudy obj = context.TwitterStudies
                .Where(where1 => where1.Name == name)
                .FirstOrDefault();
            return obj;
        }
        public List<TwitterStudy> GetByUserName(string username)
        {
            TwitterUser user = new TwitterUser(){Name = username};
            List<TwitterStudy> all = context.TwitterStudies.ToList();
            return all.Where(where1 => where1.TwitterUsers.Contains(user, new Comparers.TwitterUserUserNameComparer()))
                .ToList();
        }

        public override void Add(TwitterStudy entity)
        {
            context.AddToTwitterStudies(entity);
        }

        public override void Delete(TwitterStudy entity)
        {
            context.TwitterStudies.DeleteObject(entity);
        }

        public override List<TwitterStudy> All()
        {
            return context.TwitterStudies.ToList();
        }
    }
}
